<?php

/**
 * @filename ChatUser.class.php 
 * @encoding UTF-8 
 * @author  fwz 
 * @datetime 2018-7-28  15:56:51
  */


class ChatUser {
    
    protected  $fd=0,$name='',$avatar ='',$email='',$roomid='a';
    
    public function __construct(array $options = array()){
            
            if(!empty($options)){
                foreach($options as $k=>$v){
                    if(empty($this->$k)){
                        $this->$k = $v;
                    }
                }
            }
    }
    
    public function getOnlineUsers() {
        $users = File::getOnlineUsers();
        return $users;
    }
    
    public function getUsers($roomid,$lists){
        $users = File::getUsers($roomid,$lists);
        return $users;
    }
    
    public  function save(){
        $t = time();
        $flag = File::login($this->roomid, $this->fd, array('fd'=>$this->fd,'name'=>$this->name,'email'=>  $this->email,'avatar'=>$this->avatar,'time'=>$t));
        return $flag;
    }
    
    public function getUsersByRoom($roomid){
        $lists = File::getUsersByRoom($roomid);
        $info = $this->getUsers($roomid, array_slice($lists , 0,100));
        return $info;
    }
    
    public function changeUser($oldroomid,$fd,$newroomid){
        $return = File::changeUser($oldroomid, $fd, $newroomid);
        return $return;
    }
    
    public function getUser($roomid,$fd){
        $user = File::getUser($roomid, $fd);
        return $user;
    }
    
}